package com.example.lxj.sources.controller;

import java.util.List;
import java.util.Optional;

import com.example.lxj.base.annoation.Permission;
import com.example.lxj.base.controller.BaseController;
import com.example.lxj.base.entity.AjaxRes;
import com.example.lxj.base.entity.PageDTO;
import com.example.lxj.base.entity.TableDataInfo;
import com.example.lxj.sources.entity.TbIdentificationSites;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.lxj.sources.service.ITbIdentificationSitesService;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 鉴定场所Controller
 *
 * @author lxj
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/sources/identification_sites")
public class TbIdentificationSitesController extends BaseController {
    @Autowired
    private ITbIdentificationSitesService tbIdentificationSitesService;

    /**
     * 查询鉴定场所列表
     */
    @Permission(value = "sources:identification_sites:list")
    @GetMapping("/list")
    public TableDataInfo list(TbIdentificationSites tbIdentificationSites, PageDTO pageDTO) {
        startPage(Optional.ofNullable(pageDTO.getPageNo()).orElse(1), Optional.ofNullable(pageDTO.getPageSize()).orElse(10));
        List<TbIdentificationSites> list = tbIdentificationSitesService.selectTbIdentificationSitesList(tbIdentificationSites);
        return getDataTable(list);
    }
    /**
     * 获取鉴定场所详细信息
     */
    @Permission(value = "sources:identification_sites:query")
    @GetMapping(value = "/{id}")
    public AjaxRes getInfo(@PathVariable("id") Long id) {
        return success(tbIdentificationSitesService.selectTbIdentificationSitesById(id));
    }

    /**
     * 新增鉴定场所
     */
    @Permission(value = "sources:identification_sites:add")
    @PostMapping
    public AjaxRes add(@RequestBody TbIdentificationSites tbIdentificationSites) {
        return toAjax(tbIdentificationSitesService.insertTbIdentificationSites(tbIdentificationSites));
    }

    /**
     * 修改鉴定场所
     */
    @Permission(value = "sources:identification_sites:edit")
    @PutMapping
    public AjaxRes edit(@RequestBody TbIdentificationSites tbIdentificationSites) {
        return toAjax(tbIdentificationSitesService.updateTbIdentificationSites(tbIdentificationSites));
    }

    /**
     * 删除鉴定场所
     */
    @Permission(value = "sources:identification_sites:remove")
    @DeleteMapping("/{ids}")
    public AjaxRes remove(@PathVariable("ids") Long[] ids) {
        return toAjax(tbIdentificationSitesService.deleteTbIdentificationSitesByIds(ids));
    }
}
